package com.bank.controller.login;

import com.bank.entity.login.Login_user;
import com.bank.service.login.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/dl")
public class LoginController {
    @Autowired
    private LoginService loginService;
    //去登陆界面
    @RequestMapping("/tologin")
    public String tologin(){
        return "login";
    }
    //登录查数据库
    @RequestMapping("/login")
    public String tologin(Login_user user, HttpSession session){
        System.out.println(user.getPassword());
        System.out.println(user.getUsername());
        Login_user loginUser=loginService.login(user);
        System.out.println(loginUser);
        if(loginUser!=null){
            session.setAttribute("user",loginUser);
            return "redirect:/bank/index";
        }else {
            return "dl/tologin";
        }
    }
    //去注册界面
    @RequestMapping("/tozhuce")
    public String tozhuce(){
        return "zhuce";
    }

    //注册添加
    @RequestMapping("/zhuce")
    public String zhuce(Login_user user){
        System.out.println(user.getUsername()+"---");
        System.out.println(user.getPassword()+"---");
        loginService.zhuce(user);
        return "redirect:/tologin";
    }
    //验证唯一
    @RequestMapping("/yz")
    @ResponseBody
    public boolean yz(){
        System.out.println("11");

        return false;
    }


}
